package logic

import (
	"context"
	"fmt"
	"home-manage/model"
	"strings"

	"home-manage/homerpc/homerpc"
	"home-manage/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ConsultationAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewConsultationAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConsultationAddLogic {
	return &ConsultationAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ConsultationAddLogic) ConsultationAdd(in *homerpc.ConsultationAddRequest) (*homerpc.ConsultationAddResponse, error) {
	// todo: add your logic here and delete this line

	consulatation := model.Consultation{

		Content: in.Content,
		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
	}
	if strings.Contains(in.Content, "中介费") {
		return nil, fmt.Errorf("有违规字段")
	}

	model.DB.Debug().Create(&consulatation)
	return &homerpc.ConsultationAddResponse{
		ConsultationId: int64(consulatation.ID),
	}, nil
}
